package com.nineclock.sign.controller;

import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.sigb.dto.SignAllUserDTO;
import com.nineclock.sigb.dto.SignDTO;
import com.nineclock.sigb.dto.SignPCListDTO;
import com.nineclock.sign.service.SignInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
public class SignInfoController {
    
    @Autowired
    SignInfoService signInfoService;
    
    @GetMapping("/export")
    public void exportExcel(String startTime, String endTime) throws IOException {
        signInfoService.exportExcel(startTime, endTime);
    }
    
    //获取当日签到次数
    @GetMapping("/getDayCount")
    public Result<Integer> getDayCount() {
        Integer count = signInfoService.getDayCount();
        return Result.success(count);
    }
    
    
    //分页查询签到列表
    @GetMapping("/sign")
    public Result<PageResult<SignPCListDTO>> QueryAllSign(
        String startTime, String endTime,
        @RequestParam(value = "page", defaultValue = "1") Integer page,
        @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        System.out.println(startTime);
        System.out.println(endTime);
        System.out.println(page);
        System.out.println(pageSize);
        PageResult<SignPCListDTO> signPCListDTOList = signInfoService.QueryAllSign(startTime, endTime, page, pageSize);
        return Result.success(signPCListDTOList);
    }
    
    @GetMapping("/listSignAllUser")
    public Result<List<SignAllUserDTO>> listSignAllUser(@RequestParam("dateStr") String dateStr) {
        List<SignAllUserDTO> list = signInfoService.listSignAllUser(dateStr);
        return Result.success(list);
    }
    
    @PostMapping("/insert")
    public Result signAttend(SignDTO signDTO) {
        signInfoService.signAttend(signDTO);
        return Result.success();
    }
    
    @GetMapping("/pagingSignCurrentUserByMonth")
    public Result<List<SignDTO>> SignCurrentUserByMonth(String dateStr) {
        List<SignDTO> signDTOList = signInfoService.SignCurrentUserByMonth(dateStr);
        return Result.success(signDTOList);
    }
}


